//$(function(){
$("#datetimepicker").datetimepicker({
    timepicker: false,
    format:'Y-m-d'
});
$("#datetimepicker2").datetimepicker({
    timepicker: false,
    format:'Y-m-d'
})
common_request();
//})


/**
 *  默认时间设置
 * */
newTime();
$('.startdate').text($('input[name=ptime_start]').val())
$('.enddate').text($('input[name=ptime_end]').val())
//        选时间
function changeTime(){
    $('input[name=ptime_start]').on('change',function(){
        var ptime_start = $('input[name=ptime_start]').val();
        $('.startDate').text(ptime_start);
    })
    $('input[name=ptime_end]').on('change',function(){
        var ptime_end = $('input[name=ptime_end]').val();
        $('.endDate').text(ptime_end);
    })
}changeTime();


$("#lookUp1").click(function () {
    common_request();
    $('.startdate').text($('input[name=ptime_start]').val())
    $('.enddate').text($('input[name=ptime_end]').val())
});
function common_request(){
    $('.lds-css').addClass('block')
    var _d1=false,_d2=false,_d3=false
    var data_ = {
        'start_time':$('input[name=ptime_start]').val(),
        'end_time':$('input[name=ptime_end]').val(),
        inajax:1,
        r:Math.random()
    };
    $.post(serverUrl.base+serverUrl.count+'device_report',data_,function(res){
        if(res.code == '0'){
            $('.new_table2').createTable({data:res.data,columns:[
                {name:'序号',field:'',ids:1,w:'4rem'},
                {name:'设备类型',field:'device_type_name',w:'4rem'},
                {name:'设备名称',field:'device_name',w:'4rem'},
                {name:'所在网格',field:'grid_name',w:'10rem'},
                {name:'报修时间',field:'report_addtime',w:'10rem'},
                {name:'故障情况',field:'',w:'8rem',cls:'classaa',render:function(index,elm,data){
                    var list_device=data['report_file'];
                    if(list_device!=null&&list_device!=""&&(list_device.substr(list_device.length-4)=="jpeg"||list_device.substr(list_device.length-3)=="png"||list_device.substr(list_device.length-3)=="gif"||list_device.substr(list_device.length-3)=="jpg")){
                        // console.log(2)
                        list_device =''
                        var _file = data['report_file'].split(',')
                        for(var i=0;i<_file.length;i++){
                            list_device += '<img width=50 height=50 src="'+_file[i]+'" class="bigImage"/>';
                        }
                        
                    }else{
                        // console.log(1)
                        list_device = '<div></div>';
                    }
                    var list_remork = data['report_voice'];
                    // console.log(list_remork)
                    if(list_remork!=null&&list_remork.substr(list_remork.length-3)=="mp3"){
                        list_remork = '<audio controls height="80" width="80"><source src="'+data['report_voice']+'" type="audio/mpeg"><source src="'+data['report_voice']+'" type="audio/ogg"><embed height="50" width="80" src="'+data['report_voice']+'"></audio>';
                    }else{
                        list_remork='<div>'+data['report_voice']+'</div>'
                    }
                    return '<div class="img">'+list_device+'</div><div class="img">'+list_remork+'</div>'
                }},
                {name:'报修人',field:'report_user_name',w:'8rem'},
                {name:'设备管理部门',field:'department_name',w:'8rem'},
                {name:'报修状态',field:'report_status',w:'8rem',render:function(index,elm,data){
                    return elm
                }}
            ]})
        }
        
    },'json').complete(function(res){
        _d1=true
        if(_d1 && _d2 && _d3){
            $('.lds-css').removeClass('block')
        }
    }).error(function(res){

    })
    $.post(serverUrl.base+serverUrl.count+'information_report',data_,function(res){
        if(res.code == '0'){
            $('.new_table3').createTable({data:res.data,columns:[
                {name:'序号',field:'',ids:1,w:'4rem'},
                {name:'信息一级类别',field:'first_information_type_name',w:'4rem'},
                {name:'信息二级类别',field:'information_type_name',w:'4rem'},
                {name:'问题描述',field:'information_title',w:'10rem'},
                {name:'所属网格',field:'grid_name',w:'10rem'},
                {name:'上报时间',field:'information_addtime',w:'8rem'},
                {name:'上报内容',field:'information_content',w:'8rem'},
                {name:'上报人',field:'user_name',w:'8rem'},
                {name:'所在部门',field:'department_name',w:'8rem'}
            ]})
        }
        
    },'json').complete(function(res){
        _d2=true
        if(_d1 && _d2 && _d3){
            $('.lds-css').removeClass('block')
        }
    }).error(function(res){

    })
    $.ajax({
        type:"post",
        url: serverUrl.base+serverUrl.count+'grid_task_table' ,
        data: data_,
        dataType:"json",
        success: function(res){
            var list = res.data;
            // console.log(list)
            $('.new_table1').createTable({data:list,columns:[
                {name:'序号',field:'',ids:1,w:'4rem'},
                {name:'工号',field:'user_account',w:'4rem'},
                {name:'姓名',field:'user_name',w:'4rem'},
                {name:'所在部门',field:'department_name',w:'10rem'},
                {name:'巡视网格',field:'xs_grid',w:'10rem'},
                {name:'设备报修次数',field:'device_report_num',w:'8rem'},
                {name:'卫生上报次数',field:'health_report_num',w:'8rem'},
                {name:'安全上报次数',field:'safe_report_num',w:'8rem',cls:'anqtime',render:function(index,elm,data){
                    var _text = elm + '</b><span class="spread black_act '
                    if(elm == '0'){
                        _text += 'none'
                    }else{
    
                    }
                    _text += '">展开</span>'
                    var _info = data.info
                    var _html='<div class="hide none">'
                    for(var i=0;i<_info.length;i++){
                        _html +='<p class="p_hide">'+_info[i].information_type_name+'：<span class="Zero">'+_info[i].number+'</span></p>'
                    }
                    _html +='</div>'
                    _text +=_html
                    _text +='</td>' 
                    return _text
                }}
            ]})
            //showlist();
            // antime();
            // tdZero();
        },
        complete:function(){
            _d3=true
            if(_d1 && _d2 && _d3){
                $('.lds-css').removeClass('block')
            }
        },
        error:function(res){
            _d3=true
            if(_d1 && _d2 && _d3){
                $('.lds-css').removeClass('block')
            }
            console.log('error',res)
        }
    })
}
// 安全信息上报次数
$(".station_shaow_detail_table").on('click','.spread',function(){
    var this_=$(this)
    var PID = $(this).parents('tr').attr('rel');
    if(this_.hasClass('black_act')&&this_.text()=="展开"){
        this_.removeClass('black_act').addClass('black2_act');
        this_.siblings('.hide').removeClass('none')
        this_.text("收起"); 

    }else if(this_.hasClass('black2_act')&&this_.text()=="收起"){
        this_.text("展开");
        this_.removeClass('black2_act').addClass('black_act');
        this_.parents('.anqtime').children('.hide').addClass('none')
    } 
})
// 如果是0不显示展开和收起
// function antime(){
//     var bstyle=$(".bstyle");
//     $.each(bstyle,function(i,o){
//         if($(this).text()=="0"||$(this).text()=="null"||$(this).text()==""){
//             $(this).siblings('.spread').addClass('none');
//         }else{
//             $(this).siblings('.spread').removeClass('none');
//         }
//     })
// }
// 如果脱岗次数为0，脱岗网格不显示
// function tdZero(){
//     var td_zero=$(".td_zero");
//     $.each(td_zero,function(i,o){
//         if($(this).text()=="0"){
//             $(this).siblings('.zero_td').text('');
//         }
//     })
// }
function print(){
    $(".station_shaow_detail").jqprint();
}   